<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改产品类型')" />
    <th:block th:include="include :: datetimepicker-css" />
    <style>
        .success{
            color: yellowgreen;
        }
        .error{
            color: orangered;
        }
    </style>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-type-edit" th:object="${oProductType}">
        <input name="id" th:field="*{id}" type="hidden">
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">类型名称：</label>
            <div class="col-sm-8">
                <input name="productName" th:field="*{productName}" class="form-control" type="text" required>
                <span class="productName"></span>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">类型代码：</label>
            <div class="col-sm-8">
                <input name="productCode" th:field="*{productCode}" class="form-control" type="text" required>
                <span class="productCode"></span>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">排序：</label>
            <div class="col-sm-8">
                <input name="sortOrder" th:field="*{sortOrder}" class="form-control" type="text" required>
                <span class="sortOrder">数字越大排的越前面,范围0-999</span>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: datetimepicker-js" />
<script th:inline="javascript">
    var prefix = ctx + "product/productType";
    $("#form-type-edit").validate({
        focusCleanup: true
    });

    //数据格式验证
    $("input[name=productCode]").on("change",function () {
        var text = $("input[name=productCode]").val();
        if ($.common.enValid(text)){
            $(".productCode").html("验证通过");
            $(".productCode").removeClass('error').addClass('success');
        }else {
            $(".productCode").html("请填写英文缩写");
            $('.productCode').addClass('error').removeClass('success');
        }
    })
    $("input[name=productName]").on("change",function () {
        var text = $("input[name=productName]").val();
        if ($.common.isNotEmpty(text)){
            $(".productName").html("验证通过");
            $(".productName").removeClass('error').addClass('success');
        }else {
            $(".productName").html("请填写产品类型名称");
            $('.productName').addClass('error').removeClass('success');
        }
    })
    $("input[name=sortOrder]").on("change",function () {
        var text = $("input[name=sortOrder]").val();
        var reg = /^[0-9][0-9]{0,2}$/;
        var flag = reg.test(text);
        if (flag){
            $(".sortOrder").html("验证通过");
            $(".sortOrder").removeClass('error').addClass('success');
        }else {
            $(".sortOrder").html("请填写排序");
            $('.sortOrder').addClass('error').removeClass('success');
        }
    })

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/edit", $('#form-type-edit').serialize());
        }
    }

    $("input[name='createDate']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });

    $("input[name='updateDate']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });
</script>
</body>
</html>
